package com.lunchEveryDay.service;

import com.lunchEveryDay.dao.BaseDao;
import com.lunchEveryDay.dao.UserDao;
import com.lunchEveryDay.dao.UserLunchDao;
import com.lunchEveryDay.entity.LunchSchedule;
import com.lunchEveryDay.entity.User;
import com.lunchEveryDay.entity.UserLunch;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Admin on 2015/7/21.
 */
@Service
public class UserLunchService extends BaseService<UserLunch,Long> {
	@Resource
	private UserLunchDao dao;
	@Override
	BaseDao getDao() {
		return dao;
	}

	public List<UserLunch> getUserLunchByUser(User user) {
		if (null==user)
			return null;
		return dao.getUserLunchByUser(user);
	}

	public List<LunchSchedule> getLunchScheduleByUser(User user) {
		if (null==user)
			return null;
		return dao.getLunchScheduleByUser(user);
	}
	public void checkLunchStatus(User user,LunchSchedule lunchSchedule,short userLunchStatus){
		UserLunch userLunch=dao.getUserLunchByUserAndLunchSchedule(user, lunchSchedule);
		if (null==userLunch) {
			userLunch = new UserLunch();
			userLunch.setUser(user);
			userLunch.setLunchSchedule(lunchSchedule);
		}
		userLunch.setStatus(userLunchStatus);
		dao.saveOrUpdate(userLunch);
	}
}
